package bb.lanxing.lib.devices.bryton;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.content.Context;
import bb.lanxing.lib.devices.api.SmartDevice;
import bb.lanxing.lib.devices.bryton.bbcp.BBDevice;
import bb.lanxing.lib.devices.bryton.bbcp.BBDeviceCallbacks;
import bb.lanxing.lib.devices.bryton.bbcp.DeviceLogFileInfo;
import bb.lanxing.lib.devices.core.AbstractPeerDevice;
import bb.lanxing.lib.devices.core.ble.IGattClient;
import java.util.AbstractMap;

public class BrytonDevice extends AbstractPeerDevice implements IGattClient, BBDeviceCallbacks {
    private BBDevice mBBDevice;
    private BrytonCallback mCallback;

    public interface BrytonCallback {
        void onDataRead(int i, int i2, byte[] bArr, AbstractMap<String, String> abstractMap);

        void onLogFileListRead(int i, DeviceLogFileInfo[] deviceLogFileInfoArr);

        void onProgressUpdate(int i);
    }

    @Override
    public BluetoothDevice getBluetoothDevice() {
        return null;
    }

    @Override
    public BluetoothGatt getBluetoothGatt() {
        return null;
    }

    @Override
    public String getCurrentFileNameInTransfer() {
        return "";
    }

    @Override
    public int getDeviceState() {
        return 17;
    }

    @Override
    public int getProtocol() {
        return 1;
    }

    @Override
    public int getType() {
        return 12;
    }

    @Override
    public void onBonded(int i) {
    }

    @Override
    public void onDataWrite(int i, int i2) {
    }

    @Override
    public void onLiveDataChanged(byte[] bArr) {
    }

    @Override
    public void onLiveDataEnabled(int i, boolean z) {
    }

    @Override
    public void onSoftwareUpdated(int i) {
    }

    @Override
    public void setDisConnectFromUser(boolean z) {
    }

    public BrytonDevice(Context context, SmartDevice smartDevice) {
        super(smartDevice);
        this.mBBDevice = new BBDevice(context);
    }

    public static boolean isDeviceConnected() {
        return BBDevice.isConnected();
    }

    @Override
    public void connect() {
        this.mBBDevice.connect(getAddress(), false, this);
    }

    @Override
    public void disconnect() {
        this.mBBDevice.abort();
        this.mBBDevice.disconnect();
    }

    @Override
    public void close() {
        this.mBBDevice.disconnect();
    }

    public void abort() {
        this.mBBDevice.abort();
    }

    public void readLogFileList() {
        this.mBBDevice.readLogFileList();
    }

    public void readLogFile(int i, byte b) {
        this.mBBDevice.readLogFile(i, b);
    }

    @Override
    public boolean isConnected() {
        return isDeviceConnected();
    }

    @Override
    public boolean isConnecting() {
        return isDeviceConnected();
    }

    @Override
    public int getConnectionState() {
        int connectionState = this.mBBDevice.getConnectionState();
        if (connectionState != -4) {
            if (connectionState == -3) {
                return 8;
            }
            if (connectionState == -2) {
                return 2;
            }
            if (connectionState == -1) {
                return 1;
            }
            if (connectionState == 0) {
                return 4;
            }
            return connectionState;
        }
        return 3;
    }

    @Override
    public void onStateChanged(int i) {
        if (i == -4) {
            notifyStateChanged(3, 0);
        } else if (i == -3) {
            notifyStateChanged(8, 0);
        } else if (i == -2) {
            notifyStateChanged(2, 0);
        } else if (i == -1) {
            notifyStateChanged(1, 0);
        } else if (i != 0) {
        } else {
            notifyStateChanged(2, 0);
        }
    }

    @Override
    public void onConnectCompleted(int i) {
        if (i == 0) {
            notifyStateChanged(2, 0);
        } else {
            notifyStateChanged(4, 0);
        }
    }

    @Override
    public void onDisconnectCompleted(int i) {
        notifyStateChanged(4, 0);
    }

    @Override
    public void onDataRead(int i, int i2, byte[] bArr, AbstractMap<String, String> abstractMap) {
        BrytonCallback brytonCallback = this.mCallback;
        if (brytonCallback != null) {
            brytonCallback.onDataRead(i, i2, bArr, abstractMap);
        }
    }

    @Override
    public void onLogFileListRead(int i, DeviceLogFileInfo[] deviceLogFileInfoArr) {
        BrytonCallback brytonCallback = this.mCallback;
        if (brytonCallback != null) {
            brytonCallback.onLogFileListRead(i, deviceLogFileInfoArr);
        }
    }

    @Override
    public void onProgressUpdate(int i) {
        BrytonCallback brytonCallback = this.mCallback;
        if (brytonCallback != null) {
            brytonCallback.onProgressUpdate(i);
        }
    }

    public void setBrytonCallback(BrytonCallback brytonCallback) {
        this.mCallback = brytonCallback;
    }

    public boolean equals(Object obj) {
        if (obj == null || !(obj instanceof BrytonDevice)) {
            return false;
        }
        return getAddress().equals(((BrytonDevice) obj).getAddress());
    }
}
